package com.tamtamy.jtta.data.xml;

import java.util.ArrayList;
import java.util.Iterator;

import org.w3c.dom.Document;

import com.tamtamy.jtta.data.OnLineUsersList;
import com.tamtamy.jtta.data.OnlineUser;
import com.tamtamy.jtta.utility.XMLUtility;

public class XMLOnLineUsersList extends OnLineUsersList {

	private static final long serialVersionUID = 2495373662959744123L;

	public XMLOnLineUsersList(Document xmlDocument) {
		super(getOnlineUsersListFromStringArray(xmlDocument));	
	}

	public static ArrayList<OnlineUser> getOnlineUsersListFromStringArray(Document xmlDocument) {
		ArrayList<OnlineUser> onlineUsersList = new ArrayList<OnlineUser>();
		ArrayList<String> onlineUsersStringList = XMLUtility.getStringList(xmlDocument, "list", "string");
		for (Iterator<String> iterator = onlineUsersStringList.iterator(); iterator.hasNext();) {
			String userID = (String) iterator.next();
			OnlineUser onlineUser = new OnlineUser(userID);
			onlineUsersList.add(onlineUser);
		}
		return onlineUsersList;
	}
}
